<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="cn.edu.scau.chentingyu.bean.student"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示学生列表</title>
</head>
<body>
	<ul>
		<%
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/jsp";
			String username = "root";
			String password = "root";
			Connection conn = DriverManager.getConnection(url, username, password);
			Statement stmt = conn.createStatement();
			String sql = "select * from tb_student";
			ResultSet rs = stmt.executeQuery(sql);
			List<student> list = new ArrayList<student>();
			while (rs.next()) { // 光标向后移动，并判断是否有效
				student student1 = new student(); // 实例化Book对象
				student1.setId(rs.getString("id")); // 对id属性赋值
				student1.setPassword(rs.getString("password"));
				student1.setName(rs.getString("name"));
				student1.setSex(rs.getString("sex"));
				student1.setAge(rs.getString("age"));
				list.add(student1); // 将图书对象添加到集合中
			}
			request.setAttribute("list", list);
		%>
		<div width="98%" align="center">
			<h2>所有学生信息</h2>
		</div>
		<table width="98%" border="0" align="center" cellpadding="0"
			cellspacing="1" bgcolor="#666666">
			<tr>
				<th bgcolor="#FFFFFF">ID</th>
				<th bgcolor="#FFFFFF">密码</th>
				<th bgcolor="#FFFFFF">学生姓名</th>
				<th bgcolor="#FFFFFF">学生性别</th>
				<th bgcolor="#FFFFFF">学生年龄</th>
			</tr>
			<%
				
				if (list == null || list.size() < 1) {
					out.print("<tr><td bgcolor='#FFFFFF' colspan='5'>没有任何图书信息！</td></tr>");
				} else {
					
					for (student student1 : list) {
			%>
			<tr align="center">
				<td bgcolor="#FFFFFF"><%=student1.getId()%></td>
				<td bgcolor="#FFFFFF"><%=student1.getPassword()%></td>
				<td bgcolor="#FFFFFF"><%=student1.getName()%></td>
				<td bgcolor="#FFFFFF"><%=student1.getSex()%></td>
				<td bgcolor="#FFFFFF"><%=student1.getAge()%></td>
			</tr>
			<%
				}
				}
			%>
		</table>
	</ul>
	<br>
	<a href="login.jsp">返回</a>
</body>
</html>
